
import Vue from 'vue'

import formatTime from '@/common/filters.js'
const changeTwoDecimal = function(x,format) {
	var f_x = parseFloat(x);
	if(isNaN(f_x)) {
		return "-";
	}
	return f_x.toFixed(format);
}

const GetGateOMCNUM = function(bs, listItem) {
	var endTime = new Date();
	var startTime;
	//泵数
	//	var bs = undefined != value["OMCNUM"] ? Number(value["OMCNUM"]) : Number("0");
	//	var listItem = value["ST_GATE_R"];
	var liststr = "";
	var listItemColor = [];
	if(bs > 0) {
		for(var i = 1; i <= bs; i++) {
			var flag = "2";
			startTime = null;
			for(var j = 0; j < listItem.length; j++) {
				if(i.toString() == listItem[j].EXKEY && "泵站状态" == listItem[j].EQPTP.toString()) {

					startTime = formatTime.convertToDate(listItem[j].TM);
					var strMinuteValue = Math.floor((endTime - startTime) / 1000 / 60);
					if(undefined != listItem[j].GTQ){
						var strValue = Number(listItem[j].GTQ);
						// 暂时不考虑最新数据时间因素，
						if(strMinuteValue <= 4320 && strValue >= 1) {
							//											strFlow += strValue;
							flag = "1";
						}else{
							flag = "0"
						}
					}
					
					// console.log(listItem[j].STCD+" = "+i+" = "+listItem[j].GTQ) 
					// console.log(listItem[j].STCD+" = "+i+" = "+flag)
					break;
				}
			}
			// console.log(i+" = "+flag)
			if(flag == "1")
				// liststr += "<view class=\"gqGreen\"></view>";
				listItemColor.push("gqGreen");
			else if(flag == "0")
				// liststr += "<view class=\"gqRed\"></view>";
				listItemColor.push("gqRed");
			else 
				// liststr += "<view class=\"gqXiu\"></view>";
				listItemColor.push("gqXiu");

			// if(i < bs) {
			// 	liststr += "&nbsp;";
			// }
		}
	} else {
		// liststr += "—";
	}
	return listItemColor;
}

const GetGateGTQNUM = function(bs, listItem) {
	var endTime = new Date();
	var startTime;
	//闸门数
//	var bs = undefined != value["GTOPNUM"] ? Number(value["GTOPNUM"]) : Number("0");
//	var listItem = value["ST_GATE_R"];
	var liststr = "";
	var listItemColor = [];
	var stcds = "";
	if(bs > 0) {
		for(var i = 1; i <= bs; i++) {
			var flag = 2;
			startTime = null;
			// var temAgg = [];
			// if (stcds.indexOf(record.STCD) > -1) {
			// 	temAgg = row.ST_GATE_R.filter(function (e) {
			// 		return e.EQPTP == "闸坝开度" && Number(e.EXKEY) == index  && new Date(convertToDate(e.TM)) > tempTM;
			// 	});			// }
			
			for(var j = 0; j < listItem.length; j++) {
				if(i.toString() == listItem[j].EXKEY && "闸坝开度" == listItem[j].EQPTP.toString()) {
					startTime = formatTime.convertToDate(listItem[j].TM);
					var strMinuteValue = Math.floor((endTime - startTime) / 1000 / 60);
					var strValue = Number(listItem[j].GTQ);
					// 暂时不考虑最新数据时间因素， 
					if(strMinuteValue <= 4320) {
						if (stcds.indexOf(listItem[j].STCD) > -1) {
							if(strValue < 0.02){
								flag = 1;
							}
						}else{
							if(strValue > 0.02){
								flag = 1;
							}
						}
					}
					break;
				}
			}
			if(flag == 1)
				listItemColor.push("gqGreenZ");
			else if(flag == 0)
				listItemColor.push("gqRedZ");
			else			
				listItemColor.push("gqXiuZ");

		}
	}
	return listItemColor;
}

export default {
	changeTwoDecimal,
	GetGateOMCNUM,
	GetGateGTQNUM
}
